package com.liuli.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.liuli.dao.UserInfoDao;
import com.liuli.entity.UserInfo;


@Repository("userdao")
@Transactional
public class UserInfoDaoImpl extends BaseDaoImpl<UserInfo> implements UserInfoDao {

	@Override
	public UserInfo login(String username, String password) {
      String hql = "from UserInfo where username=? and password=?";
      Session session =getSession();
      UserInfo userinfo =null;
      try {
    	  Query query = session.createQuery(hql);
    	  query.setParameter(0, username);
    	  query.setParameter(1, password);
    	  List<UserInfo> list = query.list();
    	  for(UserInfo u :list){
    		  userinfo = u;
    	  }
		
	} catch (Exception e) {
		 e.printStackTrace();
	}
		return userinfo; 
	}

	@Override
	public UserInfo isUserExits(String username) {
		  String hql = "from UserInfo where username=?";
	      Session session =getSession();
	      UserInfo userinfo =null;
	      try {
	    	  Query query = session.createQuery(hql);
	    	  query.setParameter(0, username);
	    	  List<UserInfo> list = query.list();
	    	  for(UserInfo u :list){
	    		  userinfo = u;
	    	  }
			
		} catch (Exception e) {
			 e.printStackTrace();
		}
			
		return userinfo;
	}

}
